#include "main/utils.h"
using namespace std;

void permutesCore(vector<int>& nums, int index, vector<vector<int>>& results) {
  if (index == nums.size()) {
    results.push_back(nums);
    return;
  }
  set<int> help_set;
  for (int i = index; i < nums.size(); ++i) {
    if (help_set.count(nums[i]) == 0) {
      help_set.insert(nums[i]);
      swap(nums, i, index);
      permutesCore(nums, index + 1, results);
      swap(nums, i, index);
    }
  }
}

vector<vector<int>> permutes(vector<int> nums) {
  vector<vector<int>> results;
  permutesCore(nums, 0, results);
  return results;
}

int main() {
  vector<int> nums = {1, 1, 2};
  auto ret = permutes(nums);
  printVec("o83", ret);

  return 0;
}
